package org.zg.library.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import org.zg.library.dao.UsersDao;
import org.zg.library.dao.impl.UsersDaoImpl;
import org.zg.library.entity.Users;
import org.zg.library.service.UsersService;

public class UsersServiceImpl implements UsersService{
	UsersDao ud = new UsersDaoImpl(); 

	@Override
	public boolean loginByUsers(Users users) {
		// TODO Auto-generated method stub
		boolean b = false;
		ResultSet rs = ud.loginByUsers(users);
		try {
			if(rs.next()) {
				b=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		return b;
	}

	@Override
	public boolean addUsers(Users users) {
		// TODO Auto-generated method stub
		int i = ud.AddUsers(users);
		if(i>0) return true;			
		return false;
	}

	@Override
	public List<Users> selectUsers(String username) {
		// TODO Auto-generated method stub
		List<Users> lv  = new ArrayList<Users>();
		ResultSet rs = ud.selectUsers(username);
		if(rs!=null){
			try {
				while(rs.next()){
					Users users = new Users();
					users.setU_id(rs.getInt(1));
					users.setU_name(rs.getString(2));
					users.setU_pwd(rs.getString(3));
					users.setU_sex(rs.getString(4));
					users.setU_tel(rs.getString(5));
					users.setU_loc(rs.getString(6));
					users.setU_date(rs.getString(7));
					lv.add(users);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return lv;
	}

	@Override
	public boolean addUsersByAdmin(Users users) {
		// TODO Auto-generated method stub
		int i = ud.AddUsersByAdmin(users);
		if(i>0) return true;			
		return false;
	}

	@Override
	public List<Users> getUsers(int id) {
		// TODO Auto-generated method stub
		List<Users> lv  = new ArrayList<Users>();
		ResultSet rs = ud.getUsers(id);
		if(rs!=null){
			try {
				while(rs.next()){
					Users users = new Users();
					users.setU_id(rs.getInt(1));
					users.setU_name(rs.getString(2));
					users.setU_pwd(rs.getString(3));
					users.setU_sex(rs.getString(4));
					users.setU_tel(rs.getString(5));
					users.setU_loc(rs.getString(6));
					users.setU_date(rs.getString(7));
					lv.add(users);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return lv;
	}

	@Override
	public boolean updateUsers(Users users) {
		// TODO Auto-generated method stub
		int i = ud.updateUsers(users);
		if(i>0) return true;			
		return false;
	}

	@Override
	public boolean deleteUsers(int id) {
		// TODO Auto-generated method stub
		int i = ud.deleteUsers(id);
		if(i>0) 
			return true;
		return false;
	}

	@Override
	public int getTotalCount() {
		// TODO Auto-generated method stub
		return ud.getTocalCount();
	}

	@Override
	public List<Users> getUsersCurrentPage(int currentPage, int pageSize) {
		// TODO Auto-generated method stub
		return ud.getUsersCurrentPage(currentPage, pageSize);
	}
}
